<template src="./UserpaymentDetails.html"/>
<script>
import * as api from "../../api/api";
export default {
    data() {
        return {
            startValue: "", // 开始时间
            endValue: "", // 结束时间
            clearable: false,
            dialogVisible: false, //撤销弹窗 是否展现
            dataValue: "", // 时间选择框
            pachActionType: "", //弹窗确认类型
            userName: "", // 收款人姓名
            mobile: "", // 收款人的手机号
            status: -1, // 状态
            type: 0, //打款方式 默认是银行打款
            recordIds: [], //批量操作的列表
            statusData: [], // 状态列表
            tableData: [], // 数据列表
            currentPage: 1, // 当前页数
            pageCount: 1, // 总条数

            ListLoading: false
        };
    },
    methods: {
        // 查询
        onSubmit() {
            this.startValue = "";
            this.endValue = "";
            if (this.dataValue) {
                this.startValue = this.dataValue[0];
                this.endValue = this.dataValue[1];
            }
            this.currentPage = 1; //将页码置为第一页
            this.userWithdrawalRecordList();
        },
        // 导出excel
        extractExcel() {
            api.downloadUserWithdrawalRecordList({
                type: this.type,
                updateTimeStart: this.startValue,
                updateTimeEnd: this.endValue,
                userName: this.userName,
                status: this.status,
                mobile: this.mobile
            });
        },
        // 分页点击方法
        handleCurrentChange(val) {
            this.currentPage = val;
            this.userWithdrawalRecordList();
        },
        // 获取状态列表
        userWithdrawalStatus(data) {
            api.getUserWithdrawalStatus(data).then(res => {
                this.statusData = res.data;
                this.status = res.data[0].code;

                this.userWithdrawalRecordList();
            });
        },
        // 获取用户打款明细
        userWithdrawalRecordList() {
            this.ListLoading = true;
            api.getUserWithdrawalRecordList({
                type: this.type,
                pageNum: this.currentPage,
                updateTimeStart: this.startValue,
                updateTimeEnd: this.endValue,
                userName: this.userName,
                mobile: this.mobile,
                status: this.status,
                pageSize: 10
            }).then(res => {
                this.ListLoading = false;
                this.tableData = res.data.list.map(item => {
                    if (item.status !== "3") {
                        item.remark = "";
                    }
                    return item;
                });

                this.pageCount = res.data.pages;
            });
        },
        // tab切换
        tabClick() {
            this.ListLoading = true;
            api.getUserWithdrawalRecordList({
                type: this.type,
                pageNum: this.currentPage,
                updateTimeStart: this.startValue,
                updateTimeEnd: this.endValue,
                userName: this.userName,
                mobile: this.mobile,
                status: this.status,
                pageSize: 10
            }).then(res => {
                this.ListLoading = false;

                this.tableData = res.data.list.map(item => {
                    if (item.status !== "3") {
                        item.remark = "";
                    }
                    return item;
                });
                console.log(this.tableData);
                this.pageCount = res.data.pages;
            });
        },
        // 选择批量操作
        handleSelectionChange(val) {
            val.forEach(item => {
                if (item.status !== "1") {
                    this.$refs.multipleTable.toggleRowSelection(item);
                }
            });
            this.recordIds = val.map(item => {
                return item.autoId;
            });
        },
        // 微信打款 -批量
        wxpay() {
            this.dialogVisible = false;
            const recordIds = this.recordIds.join(",");
            api.wxpay({ recordIds }).then(res => {
                const { totalCount, successCount, failCount } = res.data;
                this.$message.success(
                    `批量操作${totalCount}条记录，成功${successCount}条，失败${failCount}条`
                );
                setTimeout(() => {
                    this.userWithdrawalRecordList();
                }, 600);
            });
        },
        wxpaySure() {
            if (this.recordIds.length === 0) {
                this.$message.info("请选择要操作的记录，可多选");
                return;
            }
            this.dialogVisible = true;
            this.pachActionType = "wxpay";
        },
        // 微信打款订单 取消 - 批量
        wxreturn() {
            if (this.recordIds.length === 0) {
                this.$message.info("请选择要操作的记录，可多选");
                return;
            }
            this.dialogVisible = true;
            this.pachActionType = "wxreturnSure";
        },
        sureAction() {
            if (typeof this[this.pachActionType] === "function") {
                this[this.pachActionType]();
            }
        },
        wxreturnSure() {
            this.dialogVisible = false;
            const recordIds = this.recordIds.join(",");
            console.log(typeof recordIds);

            api.wxreturn({ recordIds }).then(res => {
                const { totalCount, successCount, failCount } = res.data;
                this.$message.success(
                    `批量操作${totalCount}条记录，成功${successCount}条，失败${failCount}条`
                );
                setTimeout(() => {
                    this.userWithdrawalRecordList();
                }, 600);
            });
        },
        // radio切换
        radioChange(autoId, status) {
            this.$confirm("是否确认修改操作?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            })
                .then(() => {
                    this.updateUserWithdrawal(autoId, status);
                })
                .catch(() => {
                    this.userWithdrawalRecordList();
                    this.$message({
                        type: "info",
                        message: "已取消"
                    });
                });
        },
        // 更新打款明细状态
        updateUserWithdrawal(autoId, status) {
            api.updateUserWithdrawalRecord({
                autoId: autoId,
                status: status
            }).then(res => {
                this.$message.success("状态变更成功!");
                this.userWithdrawalStatus();
            });
        }
    },
    mounted() {
        const { mobile } = this.$route.query;
        this.mobile = mobile;
        // 获取状态列表
        this.userWithdrawalStatus();
    }
};
</script>

<style>
.userpayClassName .cell {
    text-align: left;
}
.userpayCellClassName .el-radio + .el-radio {
    margin-left: 0px;
}
</style>
